﻿using LuDragon.Common.Utils;
using LuDragon.Data.Entities;
using LuDragon.IService.System;
using LuDragon.Service.System;
using System.Web.Mvc;

namespace LuDragon.Web.Areas.Admin.Filters
{
    public class CheckLogin : FilterAttribute, IActionFilter
    {
        /// <summary>
        /// Action执行之前
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            IUserService userService = new UserService();
            var AdminInfo = userService.GetCurrentUser();
            if (AdminInfo == null)
            {               
                filterContext.Result = new RedirectResult($"/Admin/Login/Index");
                return;
                //filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { controller = "Login", action = "Index" }));
            }
        }
        /// <summary>
        /// Action执行之后
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }
    }
}